<template>
  <div>
    <el-dialog
      title="添加扣款"
      width="700px"
      class="icon-dialog"
      :visible="true"
      :before-close="closeForm"
      append-to-body
      @close="closeForm"
    >
      <el-form
        ref="form"
        :size="size"
        :model="form"
        :rules="rules"
        :label-width="$store.getters.device !== 'mobile' ? '16%' : '90px'"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="扣款人" prop="uuid">
              <el-select
                v-model="form.uuid"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in technicalList"
                  :key="item.val"
                  :label="item.key"
                  :value="item.val"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="金额" prop="price">
              <el-input v-model="form.price" placeholder="请输入扣款金额" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="扣款原因" prop="description">
              <el-input
                v-model="form.description"
                type="textarea"
                :rows="4"
                placeholder="请输入扣款原因"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="loading" type="primary" @click="submit">
          <span v-if="!loading">确 定</span>
          <span v-else>提 交 中...</span>
        </el-button>
        <el-button @click="closeForm">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  <script>
export default {
  name: "technicalcategoryupdate",
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    opentype: {
      type: String,
      default: "add",
    },
    size: {
      type: String,
      default: "small",
    },
    technicalList: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      dialogtitle: "",
      form: {
        uuid: "",
        price: "",
        description: "",
      },
      loading: false,
      rules: {
        uuid: [
          {
            required: true,
            message: "扣款人不能为空",
            trigger: "change",
          },
        ],
        price: [
          {
            required: true,
            message: "扣款金额不能为空",
            trigger: "blur",
          },
        ],
        description: [
          {
            required: true,
            message: "扣款原因不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {
    show(val) {},
  },
  methods: {
    submit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$api
            .post("/Technicaldeduct/add", this.form)
            .then((res) => {
              if (res.errno == 0) {
                this.$message({
                  message: res.msg,
                  type: "success",
                });
                this.$emit("save");
                this.closeForm();
              } else {
                this.loading = false;
                this.$message({
                  message: res.msg,
                  type: "error",
                });
              }
            })
            .catch(() => {
              this.loading = false;
            });
        }
      });
    },
    closeForm() {
      this.$emit("cancel");
      this.loading = false;
      if (this.$refs["form"] !== undefined) {
        this.$refs["form"].resetFields();
      }
    },
  },
};
</script>
  